@extends('home.parent')
@section('title','操作日志列表')
@section('head_js')
@endsection
@section('head_css')
<link rel="stylesheet" href="{{ asset('/css/dataTables.bootstrap.css') }}">
<style>
  .code{
    padding: 2px 4px;
    word-wrap:break-word;
    overflow:hidden;
    word-break:break-all;
    font-size: 90%;
    color: #c7254e;
    background-color: #f9f2f4;
    border-radius: 4px;
  }
</style>
@endsection
@section('content')
<div class="content-wrapper">
    <section class="content-header">
      <h1>
        操作日志列表
        <small></small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="{{URL('admin')}}"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li class="active">操作日志列表</li>
      </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box"> 
                    <div class="box-body">
                        <table id="data_list" class="table table-bordered table-striped">
                            <thead>
                              <tr>
                                <th>编号</th>
                                <th>姓名</th>
                                <th>方法</th>
                                <th>路径</th>
                                <th>Ip</th>
                                <th style="width:450px;">Input</th>
                                <th>创建时间</th>
                              </tr>
                            </thead>
                            <tbody>
                            </tbody>
                            <tfoot>
                              <tr>
                                <th>编号</th>
                                <th>姓名</th>
                                <th>方法</th>
                                <th>路径</th>
                                <th>Ip</th>
                                <th style="width:450px;">Input</th>
                                <th>创建时间</th>
                              </tr>
                            </tfoot>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
        </div>
    </section>
</div>
@endsection
@section('foot_js')
<script src="{{ asset('/js/jquery.dataTables.js') }}"></script>
<script src="{{ asset('/js/dataTables.bootstrap.min.js') }}"></script>
<script src="{{ asset('/js/jquery.slimscroll.min.js') }}"></script>
<script src="{{ asset('/js/fastclick.js') }}"></script>
<script src="{{ asset('/js/tools.js').'?v='.env('VERSION') }}"></script>
<script>
var list_ajax;
$(function () {
  //提示信息
  var lang = puppet.langShow();
  //初始化表格
  list_ajax = $("#data_list").dataTable({
    language:lang,  //提示信息
    autoWidth: false,  //禁用自动调整列宽
    stripeClasses: ["odd", "even"],  //为奇偶行加上样式，兼容不支持CSS伪类的场合
    processing: true,  //隐藏加载提示,自行处理
    serverSide: true,  //启用服务器端分页
    searching: false,  //禁用原生搜索
    orderMulti: false,  //启用多列排序
    order: [[0,'desc']],  //取消默认排序查询,否则复选框一列会出现小箭头
    renderer: "bootstrap",  //渲染样式：Bootstrap和jquery-ui
    pagingType: "simple_numbers",  //分页样式：simple,simple_numbers,full,full_numbers
    lengthMenu:[10,20,50,100], //更改显示记录数选项 
    displayLength:10, //默认显示的记录数
    columnDefs: [
      {
      "targets": [1,2,3,4,5,6],  //列的样式名
      "orderable": false    //包含上样式名‘nosort’的禁止排序
      },
      {
        targets:2,
        data:"method",
        render: function (data, type, row, meta) {
          switch(data){
            case 'GET':
              return '<span class="badge bg-green">GET</span>';
              break;
            case 'POST':
              return '<span class="badge bg-yellow">POST</span>';
              break;
            case 'PUT':
              return '<span class="badge bg-blue">PUT</span>';
              break;
            case 'DELETE':
              return '<span class="badge bg-red">DELETE</span>';
              break;
          }
        }
      },
      {
        targets:3,
        data:"path",
        render: function (data, type, row, meta) {
          return '<span class="label label-info">'+data+'</span>';
        }
      },
      {
        targets:4,
        data:"ip",
        render: function (data, type, row, meta) {
          return '<span class="label label-primary">'+data+'</span>';
        }
      },
      {
        targets:5,
        data:"input",
        render: function (data, type, row, meta) {
          return "<div class='code'>"+data+"</div>";
        }
      },
      {
        targets: 6,
        data: "create_time",
        render: function (data, type, row, meta) {
          return (data > 0) ? puppet.formatDateTime(data*1000) : '';
        }
      },
    ],
    ajax: function (data, callback, settings) {
      //封装请求参数
      var param = {};
      param.limit = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
      param.start = data.start;//开始的记录序号
      param.page = (data.start / data.length)+1;//当前页码
      param.order = data.order;
      param.search = data.search;
      $.ajax({
        type: "POST",
        url: "{{ URL('admin/action/list/ajax') }}",
        cache: false,  //禁用缓存
        data: param,   //传入组装的参数
        dataType: "json",
        success: function (result) {
          var returnData = {};
          returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回
          returnData.recordsTotal = result.total;//返回数据全部记录
          returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
          returnData.data = result.data;//返回的数据列表
          callback(returnData);
        }
      });
    },
    //列表表头字段
    columns: [
        {"data":"admin_action_id"},
        {"data":"admin_name"},
        {"data":"method"},
        {"data":"path"},
        {"data":"ip"},
        {"data":"input"},
        {"data":"create_time"},
    ],
    "fnDrawCallback":function(){
      $("#data_list_paginate").children('ul').append("<li style='margin-left:5px;'>&nbsp;&nbsp;<label style='margin-top:-5px;'>到第</lable>&nbsp;<input style='width:40px;hidden:none' class='margin text-center' id='changePage' type='text'>&nbsp;&nbsp;<label>页</lable>&nbsp;</li> <li style='margin-left:5px;float:right;' class='paginate_button'><a style='margin-bottom:5px' href='javascript:void(0);'id='dataTable-btn'>确认</a></li>");  
      var oTable = $("#data_list").dataTable();
      $('#dataTable-btn').click(function(e){
        if($("#changePage").val() && $("#changePage").val() > 0) {
          var redirectpage = $("#changePage").val() - 1;
        }else{
          var redirectpage = 0;
        }
        oTable.fnPageChange(redirectpage);
      });
    },
  }).api();
});
function actionList(id,status){
  var result = confirm('是否确认删除');
  if(result){
    var url = "{{URL('admin/action/delete')}}";
    var data = {id:id,status:status};
    var result = puppet.myajax('post',url,data,false);
    if(result.code == 1){
      puppet.mesFailure(result.msg);
      return false;
    }else{
      list_ajax.ajax.reload(null,false);
    }
  }
  return false;
}
</script>
@endsection